import Vue from 'vue'
import VueI18n from 'vue-i18n' // 引入vue-i18n插件
import zh from './zh' // 导入zh.js中文语言包
import en from './en' // 导入en.js中文语言包
import es from './es' // 导入zh.js中文语言包
Vue.use(VueI18n)
const messages = {
  en: {
    ...en // 使用ES6扩展运算符解构en
  },
  zh: {
    ...zh
  },
  es: {
    ...es
  }
}
const nav = navigator.userAgent
let isanzhuo = null
if (nav.indexOf('Android') > -1 || nav.indexOf('Adr') > -1) {
  isanzhuo = true
} else if (nav.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)) {
  isanzhuo = false
}
localStorage.getItem('lang') ? '' : (isanzhuo ? localStorage.setItem('lang', 'zh') : localStorage.setItem('lang', 'en'))
const i18n = new VueI18n({
  locale: localStorage.getItem('lang'),
  messages
})

export default i18n
